/**
 * 
 */
package ua.kpi.javatrainee6.model.people;

import ua.kpi.javatrainee6.model.curriculum.*;
import ua.kpi.javatrainee6.model.departments.*;

/**
 * UniversityAdministrator entity, contains univer, professors, subjects
 * curriculum entities
 * Provides next functionality: you can form groups, enroll students and teachers, 
 * create curricular and calculate your scholarship
 *
 */
public final class UniversityAdministrator extends Person implements Observable{
	
    private static final double BASIC_SALARY = 1500.0;
    
	private Groups groups;
	private Professors professors;
	private Subjects subjects;
	private Curriculum curriculum;
	private boolean assessmentDone = false;
	private Observers observers;
	
	/**
	 * Optional constructor - used now for automatic data generation, for more detailed description
	 * look in Person class, creating groups, professors, students, forming curriculum
	 * @param univer - reference to university, needed by list of students, professors
	 */
	public UniversityAdministrator(University univer) {
		super();
		groups = new Groups(univer, this);
		professors = new Professors(univer, groups);
		subjects = new Subjects(professors);
		groups.add(subjects);
		curriculum = new Curriculum(groups.get(0), subjects.get(0));
		observers = new Observers();
	}
	
	/**
	 * @return - indicates if performAssessment function was called
	 * and as result each student has non-empty field of marks
	 */
	public boolean isAssessmentDone() {
		return assessmentDone;
	}
	
	/**
	 * Cloning is used to avoid modifications by students or professors
	 * @return - list of groups
	 */
	public Groups getGroups() {
		return groups.copy();
	}
	
	/**
	 * Cloning is used to avoid modifications by students or professors
	 * @return - list of professors
	 */
	public Professors getProfessors() {
		return professors.copy();
	}
	
	/**
	 * Cloning is used to avoid modifications by students or professors
	 * @return - list of subjects
	 */
	public Subjects getSubjects() {
		return subjects.copy();
	}
	
	/**
	 * Cloning is used to avoid modifications by students or professors
	 * @return - list of curriculum
	 */
	public Curriculum getCurriculum() {
		return curriculum.clone();
	}
	
	/**
	 * Performing assessment for all groups and all students  and for all subjects,
	 * filling marks field of Student
	 */
	public void performAssessment() {
		assessmentDone = true;
		for (Group group : groups) {
			group.performAssessment();
		}
		notifyObservers();
	}
	
	/**
	 * Viewing all responsibilities
	 */
	public void viewResponsibilities() {
		System.out.println("YOUR RESPONSIBILITIES");
		System.out.println("As University Administrator you can :\n1. Create students groups;\n" +
				           "2. Enroll professors;\n3. Create curriculum;\n4. Perform assessment.");	
	}
	
	/**
	 * Calculating salary of administrator, is stable
	 */
	public double calculateSalary() {
		return BASIC_SALARY;
	}
	
	public void registerObserver(Observer observer) {
		observers.add(observer);
	}
	
	public void removeObserver(Observer observer) {
		observers.remove(observer);
	}
	
	public void notifyObservers() {
		observers.informAll();
	}
}

